package com.newtouch.bxzs.database.controller;

import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.database.config.MyLog;
import com.newtouch.bxzs.database.model.bo.MenuButtonBO;
import com.newtouch.bxzs.database.model.bo.MenuTreeBO;
import com.newtouch.bxzs.database.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单Controller:
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/5 10:11</td>
 * <td>zhangqianyang</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author zhangqianyang
 * @version 1.0.0
 * @since 1.0.0
 */
@RestController
@RequestMapping("/menu")
@Api(tags = "菜单查询")
@SuppressWarnings("unchecked")
public class MenuController {
    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(MenuController.class);
    @Resource
    private MenuService menuService;

    @GetMapping("/getMenuList")
    @ApiOperation("获取菜单列表")
    @MyLog(systemFunctionName = "菜单相关接口", systemFunctionUrl = "/menu/getMenuList",
            userOperationType = 4, userOperationSummary = "查询菜单列表")
    public BaseResponse<List<MenuTreeBO>> getMenuList(@RequestParam @ApiParam("所属终端类型,0查全部，1 app端，2 pc端") String terminalType) {
        logger.info("获取菜单列表");
        List<MenuTreeBO> res = menuService.getMenuList(terminalType);
        return RespGenerator.returnOK(res);
    }

    @PostMapping("/getMenuButtonList")
    @ApiOperation("获取选中菜单的按钮列表")
    @MyLog(systemFunctionName = "菜单相关接口", systemFunctionUrl = "/menu/getMenuButtonList",
            userOperationType = 4, userOperationSummary = "查询菜单的按钮列表")
    public BaseResponse<List<MenuButtonBO>> getMenuButtonList(@RequestBody @ApiParam(value = "菜单id,不用写参数名", required = true) List<String> menuIdList) {
        logger.info("获取选中菜单的按钮列表");
        List<MenuButtonBO> res = menuService.getMenuButtonList(menuIdList);
        return RespGenerator.returnOK(res);
    }

}
